package com.slien.vt.util;

import java.util.ArrayList;
import java.util.List;

//分页对象
public class Page<T> extends ArrayList<T> {

    private int pageNo = 1;     //默认第一页
    private int pageSize = 15;  //默认15条记录
    private int totalRecord; //记录总数
    private int totalPage; //总页数
    private List<T> result;

    public Page(){}

    public Page(int pageNo,int pageSize, int totalRecord, List<T> result){
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalRecord = totalRecord;
        this.setResult(result);
        int totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
        this.setTotalPage(totalPage);
    }

    private void setResult(List<T> result) {
        this.result = result;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRecord() {
        return totalRecord;
    }

    public void setTotalRecord(int totalRecord) {
        this.totalRecord = totalRecord;
        //设置总记录数时就算出对应的总页数
        int totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
        this.setTotalPage(totalPage);
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getResult() {
        return result;
    }
}
